<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <img src="images/fruit.jpg" id="s1" alt="水果图片" /><br />
    <input name="b1" type="button" value="改变图片" onclick="change()" />
    <input name="b2" type="button" value="显示图片路径" onclick="show()" />

    <script type="text/javascript">
      function change() {
        var imgs = document.getElementById("s1");
        imgs.src = "images/grape.jpg";
      }
      function show() {
        var hText = document.getElementById("s1").alt;
        alert("图片的alt是：" + hText);
      }
    </script>
  </body>
</html>
